﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wicresoft.EKA.ITSM.Business;
using Wicresoft.EKA.ITSM.BusinessImpl;
using Ninject;
using Wicresoft.EKA.MVCExtensions;
using System.Drawing;

namespace Wicresoft.EKA.ITSM.Web.WebPortal.Controllers
{
    public class HomeController : BaseController
    {
        [Inject]
        public ICTMPeople CTMPeople { get; set; }

        [Inject]
        public ISMGXJGroupAsso SMGXJGroupAsso { get; set; }

        [Inject]
        public IUser User { get; set; }

        [Inject]
        public override IUserInfo UserInfo { get; set; } //每个Controller必须包含的

        protected override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
        {
            ((IBase)User).UserIdentify = UserName;
            ((IBase)CTMPeople).UserIdentify = UserName;
            ((IBase)SMGXJGroupAsso).UserIdentify = UserName;
            base.OnActionExecuting(filterContext);
        }

        protected override void Dispose(bool disposing)
        {
            ((IDisposable)User).Dispose();
            ((IDisposable)CTMPeople).Dispose();
            ((IDisposable)SMGXJGroupAsso).Dispose();
            base.Dispose(disposing);
        }

        [Permission(IsPublic = true)]
        public ActionResult InspectionConsole()
        {
            string agent = Request.Headers["User-Agent"];
            if (Helper.choose_net(agent)) {
                Response.Redirect("/Home/InspectionConsoleMobile");                
            }
            ViewBag.Excute = User.GetGroupAsso(UserName, "No").Where(o => o.GroupName == "巡检执行人").Count();
            ViewBag.OfficeSelection = SMGXJGroupAsso.GetGroupName(UserName);
            return View();
        }

        [Permission(IsPublic = true)]
        public ActionResult InspectionConsoleMobile()
        {
            ViewBag.Excute = User.GetGroupAsso(UserName, "No").Where(o => o.GroupName == "巡检执行人").Count();
            ViewBag.OfficeSelection = SMGXJGroupAsso.GetGroupName(UserName);
            return View();
        }

        [Permission(IsPublic = true)]
        public ActionResult MyTask()
        {
            ViewBag.FullName = UserName;
            return View();
        }

        [Permission(IsPublic = true)]
        public ActionResult MyTaskMobile()
        {
            ViewBag.FullName = UserName;
            return View();
        }

        [Permission(IsPublic = true)]
        public ActionResult TaskFrameSearch()
        {
            ViewBag.FullName = UserName;
            ViewBag.OfficeSelection = SMGXJGroupAsso.GetGroupName(UserName).Select(o => o.GroupName);
            return View();
        }

        public ActionResult Permission()
        {
            ViewBag.fullname = CTMPeople.GetPeopleByLoginID(UserName).FullName;
            ViewBag.loginname = UserName;
            return View();
        }
        
    }
}
